
package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.ServiceAreaAddParam;
import com.xin.di.uav.applet.request.ServiceAreaEditParam;
import com.xin.di.uav.common.response.IdAndNameResp;
import com.xin.di.uav.applet.resp.ServiceAreaResp;
import com.xin.di.uav.applet.service.ServiceAreaService;
import com.xin.di.uav.common.request.common.IdRequest;
import com.xin.di.uav.common.utils.Rs;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/home/service-area/")
public class ServiceAreaController {
    @Autowired
    private ServiceAreaService serviceAreaService;

    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid ServiceAreaAddParam serviceArea) {
        return Rs.success(serviceAreaService.add(serviceArea));
    }

//    @DeleteMapping("{id}")
//    public Rs<Boolean> delete(@PathVariable String id) {
//        return Rs.success(serviceAreaService.delete(id));
//    }

    @PutMapping("update")
    public Rs<Boolean> update(@RequestBody @Valid ServiceAreaEditParam serviceArea) {
        return Rs.success(serviceAreaService.update(serviceArea));
    }

    @PutMapping("update-status")
    public Rs<Boolean> updateStatus(@RequestBody @Valid IdRequest idRequest) {
        return Rs.success(serviceAreaService.updateStatus(idRequest));
    }

//    @GetMapping("{id}")
//    public Rs<ServiceAreaPO> getById(@PathVariable String id) {
//        return Rs.success(serviceAreaService.getById(id));
//    }

    @GetMapping("list")
    public Rs<ServiceAreaResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String name) {
        return Rs.success(serviceAreaService.list(page, pageSize, name));
    }


    @GetMapping("get-id-and-name")
    public Rs<List<IdAndNameResp>> getIdAndName(@RequestParam() @NotBlank(message = "搜索名称不能为空") String serviceRegion) {
        return Rs.success(serviceAreaService.getIdAndName(serviceRegion));
    }
}
